package com.ctg.itrdc.sysmgr.portal.data.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.pasp.core.PageInfo;
import com.ctg.itrdc.pasp.data.dao.BaseDao;
import com.ctg.itrdc.sysmgr.portal.data.ISystemUserDao;
import com.ctg.itrdc.sysmgr.portal.data.entity.SystemUser;
import com.ctg.itrdc.sysmgr.portal.data.vo.SystemUserVO;

@Component("systemUserDao")
public class SystemUserDaoImpl extends BaseDao<SystemUser, Long> implements
		ISystemUserDao {

	private final static String IN = "in";
	private final static String NOT_IN = "not in";

	@Override
	public PageInfo<SystemUser> selectByOrgId(SystemUser entity, Long orgId,
			int currentPage, int perPageNum) {
		Map<String, Object> model = new HashMap<String, Object>(2);
		model.put("su", entity);
		model.put("orgId", orgId);
		return pageBySqlId("selectByOrgId", currentPage, perPageNum, model);
	}

	@Override
	public PageInfo<SystemUserVO> excludeByIds(SystemUserVO systemUser,
			List<Long> idList, int currentPage, int perPageNum) {
		return includeAndExcludeByIds(systemUser, idList, currentPage,
				perPageNum, NOT_IN);
	}

	@Override
	public PageInfo<SystemUserVO> includeByIds(SystemUserVO systemUser,
			List<Long> idList, int currentPage, int perPageNum) {
		return includeAndExcludeByIds(systemUser, idList, currentPage,
				perPageNum, IN);
	}

	private PageInfo<SystemUserVO> includeAndExcludeByIds(
			SystemUserVO systemUser, List<Long> idList, int currentPage,
			int perPageNum, String inOrEx) {
		Map<String, Object> model = new HashMap<String, Object>(3);
		model.put("systemUser", systemUser);
		model.put("idList", idList);
		model.put("inOrEx", inOrEx);
		return pageBySqlId("includeAndExcludeByIds", SystemUserVO.class,
				currentPage, perPageNum, model, null);
	}

}